package com.ebelter.bodyfatscale.ui.view.dialogs;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.ebelter.bodyfatscale.R;


/**
 * desc:文本提示对话框
 */
public class LoadingDialog extends Dialog{
    private Context mContext;


    private ProgressBar mPb;
    private TextView mTip;





    public LoadingDialog(Context context) {
        super(context, R.style.dialog);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setCanceledOnTouchOutside(false);
        this.mContext = context;


    }



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        final View view = View.inflate(mContext, R.layout.loadingdialog_ly, null);
        mPb=view.findViewById(R.id.laoding_pb);
        mTip=view.findViewById(R.id.laoding_tv);

        view.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                view.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                Window dialogWindow = getWindow();
                if (dialogWindow != null) {
                    WindowManager.LayoutParams lp = dialogWindow.getAttributes();
                    DisplayMetrics d = mContext.getResources().getDisplayMetrics();
                   // int maxOne = Math.max(d.widthPixels, d.heightPixels);
                    int minOne = Math.min(d.widthPixels, d.heightPixels);
                  //  lp.width = (int) (minOne * 0.82);
//                    lp.height = (int) (minOne * 0.3);
                   // lp.width= DipUtil.dip2px(getContext(),288);
                    lp.width= LinearLayout.LayoutParams.WRAP_CONTENT;
                    lp.height= LinearLayout.LayoutParams.WRAP_CONTENT;
                    dialogWindow.setAttributes(lp);
                }
            }
        });
        setContentView(view);
    }

    public void setTip(String tip) {
        mTip.setText(tip);
    }
}
